[XEN][POWERPC] The VIO rewrite
authorJimi Xenidis <jimix@watson.ibm.com>
Fri, 3 Nov 2006 21:53:17 +0000 (16:53 -0500)
committerJimi Xenidis <jimix@watson.ibm.com>
Fri, 3 Nov 2006 21:53:17 +0000 (16:53 -0500)
Once you figure it all out, its time to do a rewrite, lots of code I
thougth I needed is now removed and less PPC specific code now exists.
This patch uses the MEMORY_HOTPLUG system to add a region to the
Kernel Linear Mapping that will be used exclusively to map in
Granted/Foreign pages.  This creates "struct page" objects in Linux
which are necessary to perform VIO operations.  When one of these
pages are grant_mapped the pfn2mfn() translation in Xen is updated to
reflect the association and the subsequent H_ENTER() from the domain
will contain the correct mapping.
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
xen/arch/powerpc/domain.c
xen/arch/powerpc/mm.c
xen/arch/powerpc/ofd_fixup.c
xen/include/asm-powerpc/domain.h
xen/include/asm-powerpc/grant_table.h

index f2fe28048cd63617fef129803cedd4163860b8a7..31a594d03cea1ee6360b0b1ad9c6bc1a73b50c8e 100644 (file)
@@ -88,6 +88,12 @@ int arch_domain_create(struct domain *d)
 
     INIT_LIST_HEAD(&d->arch.extent_list);
 
+    d->arch.foreign_mfn_count = 1024;
+    d->arch.foreign_mfns = xmalloc_array(uint, d->arch.foreign_mfn_count);
+    BUG_ON(d->arch.foreign_mfns == NULL);
+
+    memset(d->arch.foreign_mfns, -1, d->arch.foreign_mfn_count * sizeof(uint));
+
     return 0;
 }
 
@@ -294,6 +300,7 @@ void domain_relinquish_resources(struct domain *d)
     relinquish_memory(d, &d->xenpage_list);
     relinquish_memory(d, &d->page_list);
     free_extents(d);
+    xfree(d->arch.foreign_mfns);
     return;
 }
 
index 8a91cbe51dbd5f4cf2e3674b99308fd50b50e7d1..d6bc94b4a5bf1a0e7c58a6aac7d45d8e29ebe8f0 100644 (file)
@@ -93,6 +93,26 @@ void share_xen_page_with_privileged_guests(
         unimplemented();
 }
 
+static ulong foreign_to_mfn(struct domain *d, ulong pfn)
+{
+
+    pfn -= 1UL << cpu_foreign_map_order();
+
+    BUG_ON(pfn >= d->arch.foreign_mfn_count);
+
+    return d->arch.foreign_mfns[pfn];
+}
+
+static int set_foreign(struct domain *d, ulong pfn, ulong mfn)
+{
+    pfn -= 1UL << cpu_foreign_map_order();
+
+    BUG_ON(pfn >= d->arch.foreign_mfn_count);
+    d->arch.foreign_mfns[pfn] = mfn;
+
+    return 0;
+}
+
 static int create_grant_va_mapping(
     unsigned long va, unsigned long frame, struct vcpu *v)
 {
@@ -101,6 +121,7 @@ static int create_grant_va_mapping(
         BUG();
         return GNTST_permission_denied;
     }
+    set_foreign(v->domain, va >> PAGE_SHIFT, frame);
     return GNTST_okay;
 }
 
@@ -112,6 +133,7 @@ static int destroy_grant_va_mapping(
         BUG();
         return GNTST_permission_denied;
     }
+    set_foreign(d, addr >> PAGE_SHIFT, ~0UL);
     return GNTST_okay;
 }
 
@@ -388,7 +410,7 @@ ulong pfn2mfn(struct domain *d, ulong pfn, int *type)
     /* quick tests first */
     if (pfn & foreign_map_pfn) {
         t = PFN_TYPE_FOREIGN;
-        mfn = pfn & ~(foreign_map_pfn);
+        mfn = foreign_to_mfn(d, pfn);
     } else if (pfn >= max_page && pfn < (max_page + NR_GRANT_FRAMES)) {
         /* Its a grant table access */
         t = PFN_TYPE_GNTTAB;
index 816fd1918920614d77e4764b2b2e01d4bcbf9f9d..3cb498dda91ceffaab1de26e6ca9909f2a319bcc 100644 (file)
@@ -354,7 +354,7 @@ static ofdn_t ofd_xen_props(void *m, struct domain *d, start_info_t *si)
 
         /* tell dom0 where ranted pages go in the linear map */
         val[0] = cpu_foreign_map_order();
-        val[1] = max_page;
+        val[1] = d->arch.foreign_mfn_count;
         ofd_prop_add(m, n, "foreign-map", val, sizeof (val));
 
         n = ofd_node_add(m, n, console, sizeof (console));
index 304cb6c9508ff2934923d6e4db9cc236c31ec80b..4c7693e4371942fc6f300b5e899f822531da46f5 100644 (file)
@@ -41,6 +41,9 @@ struct arch_domain {
     /* list of extents beyond RMA */
     struct list_head extent_list;
 
+    uint foreign_mfn_count;
+    uint *foreign_mfns;
+
     /* I/O-port access bitmap mask. */
     u8 *iobmp_mask;       /* Address of IO bitmap mask, or NULL.      */
 
index 32920dad0a53e9b865dbd6d994163a4a43ced4a6..81b1b1ed629af92898c7f97aa235be9df4a81ee8 100644 (file)
@@ -69,8 +69,4 @@ static inline uint cpu_foreign_map_order(void)
     /* 16 GiB */
     return 34 - PAGE_SHIFT;
 }
-
-#define GNTTAB_DEV_BUS(f) \
-    ((f) | (1UL << (cpu_foreign_map_order() + PAGE_SHIFT)))
-
 #endif  /* __ASM_PPC_GRANT_TABLE_H__ */